package com.tl.khadmin.controller;

import com.alibaba.fastjson.JSON;
import com.tl.khadmin.bean.GoodCat;
import com.tl.khadmin.bean.HaoLiBeiGoods;
import com.tl.khadmin.bean.OpenOrder;
import com.tl.khadmin.bean.Product;
import com.tl.khadmin.service.OrderIService;
import com.tl.khadmin.service.ProductIService;
import com.tl.khadmin.service.ProductTypeIService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author lizb
 * @date 2021-08-10
 */
@RequestMapping(value = "/api")
@Controller
public class ApiController {
    @Resource
    private OrderIService orderService;
    @Resource
    private ProductTypeIService productTypeIService;

    @Resource
    private ProductIService productIService;

    @RequestMapping(value = "/saveOrder")
    @ResponseBody
    public String saveOrder(@RequestBody String p)  {
        OpenOrder order = JSON.parseObject(p,OpenOrder.class);

        return orderService.saveOrder(order);



    }

    @RequestMapping(value = "/saveGoodsCat")
    @ResponseBody
    public String saveGoodsCat(@RequestBody String p)  {
        GoodCat cat = JSON.parseObject(p, GoodCat.class);

        return productTypeIService.syncProductType(cat);
        //return orderService.saveOrder(order);



    }


    @RequestMapping(value = "/saveGoods")
    @ResponseBody
    public String saveGoods(@RequestBody String p)  {
        HaoLiBeiGoods cat = JSON.parseObject(p, HaoLiBeiGoods.class);

        return productIService.SyncHaoLiBeiProduct(cat);
        //return productTypeIService.syncProductType(cat);
        //return orderService.saveOrder(order);



    }
}
